package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocChapterDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocChapterCommand;
import com.cskaoyan.wordmemorize.request.VocChapterPageRequest;
import com.cskaoyan.wordmemorize.service.VocChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/voc")
public class AdminVocChapterController {

    @Autowired
    VocChapterService vocChapterService;
    @SaAdminCheckPermission("admin:chapter:add")
    @PostMapping("/chapter")
    public Result addChapter(@RequestBody VocChapterCommand vocChapterCommand) {
        vocChapterService.addChapter(vocChapterCommand);
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:chapter:update")
    @PutMapping("/chapter")
    public Result updateChapter(@RequestBody VocChapterCommand vocChapterCommand) {
        vocChapterService.updateChapter(vocChapterCommand);
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:chapter:search")
    @GetMapping("/chapters/list")
    public Result<PageDTO<VocChapterDTO>> getChapterList(VocChapterPageRequest vocChapterPageRequest) {
        PageDTO<VocChapterDTO> chapterList = vocChapterService.getChapterPage(vocChapterPageRequest);
        return Result.ok(chapterList);
    }
    @SaAdminCheckPermission("admin:chapter:delete")
    @DeleteMapping("/chapter/{chapterId}")
    public Result deleteChapter(@PathVariable("chapterId") String chapterId) {
        vocChapterService.deleteChapter(Long.valueOf(chapterId));
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:chapter:batchdelete")
    @DeleteMapping("/chapters")
    public Result deleteBatchChapter(@RequestBody BatchDeleteCommand batchDeleteCommand) {
        vocChapterService.deleteChapters(batchDeleteCommand);
        return Result.ok();
    }
}
